package org.rc.model;

import com.google.gson.annotations.Expose;
import java.io.Serializable;
import org.apache.commons.lang.StringUtils;
import javax.persistence.Id;
        
public class Athlete implements Serializable {

    private static final long serialVersionUID = 1L;

    @Expose
    @Id 
    private Long id;
    @Expose
    private String firstName = "";
    @Expose
    private String secondName = "";
    @Expose
    private String club = "";
    @Expose
    private String team;
    private String facebookId;
    private String twitterId;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    /**
     * @return the club
     */
    public String getClub() {
        return club;
    }

    /**
     * @param club the club to set
     */
    public void setClub(String club) {
        this.club = club;
    }

    /**
     * @return the team
     */
    public String getTeam() {
        return team;
    }

    /**
     * @param team the team to set
     */
    public void setTeam(String team) {
        this.team = team;
    }

    /**
     * @return the facebookId
     */
    public String getFacebookId() {
        return facebookId;
    }

    /**
     * @param facebookId the facebookId to set
     */
    public void setFacebookId(String facebookId) {
        this.facebookId = facebookId;
    }

    /**
     * @return the twitterId
     */
    public String getTwitterId() {
        return twitterId;
    }

    /**
     * @param twitterId the twitterId to set
     */
    public void setTwitterId(String twitterId) {
        this.twitterId = twitterId;
    }

    /**
     * Returns true if the first name, second name and club match.
     * The name is stripped of "'" characters.
     * Case is ignored for all.
     * @param a
     * @return
     */
    public boolean equals(Object a) {
        boolean result = false;
        if (a instanceof Athlete) {
            boolean fnameMatch = this.firstName.equalsIgnoreCase(((Athlete) a).getFirstName());
            String sn1 = this.secondName.replace("'", "");
            String sn2 = ((Athlete) a).getSecondName().replace("'", "");
            result = fnameMatch
                    && sn1.equalsIgnoreCase(sn2)
                    && this.club.equalsIgnoreCase(((Athlete) a).getClub());
        }
        return result;
    }

    @Override
    public int hashCode() {
        return this.firstName.hashCode() + this.secondName.hashCode();
    }

    /**
     * @return the firstName
     */
    public String getFirstName() {
        return firstName;
    }

    /**
     * @param firstName the firstName to set
     * Formatting with first letter upper case remaining lowercase
     */
    public void setFirstName(String firstName) {
        if (firstName != null) {
            this.firstName = StringUtils.capitalize(firstName.toLowerCase());
        } else {
            this.firstName = null;
        }
    }

    /**
     * @return the secondName
     */
    public String getSecondName() {
        return secondName;
    }

    /**
     * @param secondName the secondName to set
     * Changes first letter to caps and rest to lowercase
     */
    public void setSecondName(String secondName) {
        if (secondName != null) {
            this.secondName = StringUtils.capitalize(secondName.toLowerCase());
        } else {
            this.secondName = null;
        }
    }
}
